import { Component, OnInit } from '@angular/core';
import { ApiService } from 'src/app/core/api';
import { Router, ActivatedRoute } from '@angular/router';
import { DateUtil } from 'src/app/core/util/date-util';
import { NzMessageService } from 'ng-zorro-antd';
import { I18nService } from 'src/app/core/i18n/i18n.service';

@Component({
	templateUrl: './userLog.html',
})
export class UserLogComponent implements OnInit {
	data: any = {};
	form: any = { dateType: 'today'};
	id;
	userLog;
	constructor(private i18n:I18nService ,private apiService: ApiService, private router: Router, private activeRouter: ActivatedRoute, private nzMessage:NzMessageService) {
		this.id = this.activeRouter.snapshot.queryParams['id'];
		this.i18n.get('userLog').subscribe(res=>{
			this.userLog = res;
		});
	}

	ngOnInit() {
		this.loadData();
	}
	
	loadData(){
		const date: any = {};
		if (this.form.dateType === 'today') {
			date.beginTime = DateUtil.format(DateUtil.getCurrentDate(), 'yyyy-MM-dd');
			date.endTime = DateUtil.format(DateUtil.getCurrentDate(), 'yyyy-MM-dd');
		} else if (this.form.dateType === 'week') {
			const array = DateUtil.getCurrentWeek();
			date.beginTime = DateUtil.format(array[0], 'yyyy-MM-dd');
			date.endTime = DateUtil.format(DateUtil.getCurrentDate(), 'yyyy-MM-dd');
		} else if (this.form.dateType === 'month') {
			const array = DateUtil.getCurrentWeek();
			date.beginTime = DateUtil.format(array[0], 'yyyy-MM-dd');
			date.endTime = DateUtil.format(DateUtil.getCurrentDate(), 'yyyy-MM-dd');
		}else if (this.form.dateType === 'other'){
			if(this.form.dateRange){
				date.beginTime = DateUtil.format(this.form.dateRange[0], 'yyyy-MM-dd');
				date.endTime = DateUtil.format(DateUtil.getCurrentDate(), 'yyyy-MM-dd');
			}else{
				return;
			}
		}
		this.apiService.post('行为日志详情', { id: this.id,...date }).then((res: any) => {
			this.data = res.data.userBehaviorLogDetail;
		});
	}
	changeType(){
		this.loadData();
	}
	onChange(e){
		this.loadData();
	}
	maxdate = (date)=>{
		const date1 = Number(DateUtil.format(date, 'yyyyMMdd'));
		const date2 = Number(DateUtil.format(new Date(), 'yyyyMMdd'));
		return date1 > date2;
	}
}
